<!-- 内容主体区域 -->
<link rel="stylesheet" href="layui/css/layui.css">
<div style="padding: 5px;">
    <div class="layui-tab">
        <div class="layui-tab-content">
            <div class="layui-input-inline">
                <div class="layui-input-inline">
                    <button id="add" class="layui-btn layui-btn-normal">新建篮球比赛</button>
                </div>
            </div>
            <div class="layui-input-inline">
                <form class="layui-form" action="">
                    <select id="Season" name="city" lay-verify="" lay-filter="Season">
                        <option value="">选择赛季</option>
                    </select>
                </form>
            </div>
            <table class="layui-hide" id="test" lay-filter="test"></table>

            <script type="text/html" id="orderListBar">
                {{#  if(d.State=="NULL"){ }}
                未编排
                {{#  } else if(d.State==-1) { }}
                未开赛
                {{#  } else if(d.State==0) { }}
                正在比赛
                {{#  } else if(d.State==1) { }}
                已开赛
                {{#  } }}
            </script>

            <script type="text/html" id="barDemo">
                <a class="layui-btn layui-btn-xs" lay-event="edit">修改</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            </script>

            <script type="text/html" id="BBStatistics">
                <a class="layui-btn layui-btn-xs" lay-event="BBStatistics">查看技术统计</a>
            </script>
            <script type="text/html" id="BBPicture">
                <a class="layui-btn layui-btn-xs" lay-event="BBPicture">查看比赛图片</a>
            </script>

        </div>
    </div>
</div>
<script src="https://cdn.bootcss.com/axios/0.18.0/axios.js"></script>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
<script src="layui/layui.js"></script>
<script>
    layui.use(['table', 'form'], function () {
        var table = layui.table;
        var form = layui.form;
        table.render({
            elem: '#test',
            url: 'http://svcsa.org/BBMatch?SeasonID={SeasonID}',
            parseData: function (res) {
                return {
                    "code": 0, //解析接口状态
                    "msg": '', //解析提示文本
                    "count": res.totalcount, //解析数据长度
                    "data": res.data //解析数据列表
                };
            },
            method: 'get',
            request: {
                pageName: 'page' //页码的参数名称，默认：page
                ,limitName: 'pagesize' //每页数据量的参数名，默认：limit
            },
            height : "full-108",
            title: '用户数据表',
            cols: [
                [{
                    field: 'MatchID',
                    title: 'ID',
                    width: 70,
                    fixed: 'left',
                    unresize: true,
                    sort: true,
                }, {
                    field: 'TeamAName',
                    title: '主队名',
                    width: 150,
                }, {
                    field: 'TeamBName',
                    title: '客队名',
                    width: 150,
                }, {
                    field: 'ScoreTeamA',
                    title: '主队分数',
                    width: 90,
                }, {
                    field: 'ScoreTeamB',
                    title: '客队分数',
                    width: 90,
                }, {
                    field: 'State',
                    title: '比赛状态',
                    width: 90,
                    toolbar: '#orderListBar'
                }, {
                    field: 'StartTime',
                    title: '比赛时间',
                    width: 170,
                },
                    //     {
                    //     field: 'Report',
                    //     title: '战报',
                    //     width: 150,
                    // },
                    //     {
                    //     field: 'VideoSrc',
                    //     title: '视频链接',
                    //     width: 150,
                    // },
                    {
                        field: 'SeasonName',
                        title: '赛季',
                        width: 200,
                    }, {
                    title: '查看比赛图片',
                    width: 120,
                    toolbar: '#BBPicture'
                },
                    {
                        title: '查看技术统计',
                        width: 120,
                        toolbar: '#BBStatistics'
                    }, {
                    title: '操作',
                    width: 120,
                    toolbar: '#barDemo'
                }]
            ],
            limit: 20,
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                //,curr: 5 //设定初始在第 5 页
                , groups: 1 //只显示 1 个连续页码
                , first: false //不显示首页
                , last: false //不显示尾页

            }
        });
        $("#add").click(function () {
            addUser()
        })
        //添加用户
        function addUser(){
            var index = layer.open({
                title : "新建篮球比赛",
                type : 2,
                shade: 0.8,
                area: ['100%', '100%'],
                content : "bb_match_add.html",
                success : function(layero, index){
                    var body = layer.getChildFrame('body', index);

                    setTimeout(function(){
                        layer.tips('点击此处返回用户列表', '.layui-layer-setwin .layui-layer-close', {
                            tips: 3
                        });
                    },500)
                }
            })
            layer.full(index);
            window.sessionStorage.setItem("index",index);
            //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
            $(window).on("resize",function(){
                layer.full(window.sessionStorage.getItem("index"));
            })
        }
        table.on('tool(test)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）

            if (layEvent === 'edit') { //查看
                console.log(obj.data);
                var index = layer.open({
                    title : "新建篮球比赛",
                    type : 2,
                    shade: 0.8,
                    area: ['100%', '100%'],
                    content: 'bb_match_edit.html?MatchID=' + data.MatchID,
                    success: function (layero, index) {
                        //layer.iframeAuto(index);
                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                        iframeWin.create_edi(data.Report)
                        body.find('#TeamID').attr("value", data.TeamAID)
                        body.find('#TeamID2').attr("value", data.TeamBID)
                        body.find('#SeasonID').attr("value", data.SeasonID)
                        body.find('#TeamBID').val(data.TeamBID)
                        body.find('#ScoreTeamA').val(data.ScoreTeamA)
                        body.find('#ScoreTeamB').val(data.ScoreTeamB)
//                        单选框没传过去值
                        body.find('#State').val(data.State)

                        body.find('#StartTime').val(data.StartTime)
                        // body.find('#Report').val(data.Report)
                        body.find('#VideoSrc').val(data.VideoSrc)
                        body.find('#SeasonID').val(data.SeasonID)
                        //  body.find('#MatchID').val(data.MatchID)
                        setTimeout(function(){
                            layer.tips('点击此处返回用户列表', '.layui-layer-setwin .layui-layer-close', {
                                tips: 3
                            });
                        },500)

                    },
                    end: function () {
                        location.reload();
                    }
                });
                layer.full(index);
                window.sessionStorage.setItem("index",index);
                //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
                $(window).on("resize",function(){
                    layer.full(window.sessionStorage.getItem("index"));
                })
            } else if (layEvent === 'del') {
                layer.confirm('确认删除', {
                    btn: ['确认', '取消'] //按钮
                }, function () {
                    $.ajax({
                        url: 'http://svcsa.org/BBMatch/' + data.MatchID,
                        type: 'delete',
                        dataType: 'json',
                        header: {
                            Accept: 'application/json'
                        },
                        success: function (data) {
                            console.log(data)
                        },
                        error: function (data) {
                            console.log(data)
                        }
                    });
                    layer.msg('删除成功', {
                        icon: 1,
                        time: 1200
                    }, function () {
                        location.reload();
                    });
                }, function () {
                });
            } else if (layEvent === 'BBPicture') {
                var ly = layer.open({
                    type: 2,
                    title: '查看比赛图片',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['100%', '100%'],
                    content: 'BBPicture.html?MatchID=' + data.MatchID,
                    success: function (layero, index) {
                        layer.iframeAuto(index);

                    },
                    end: function () {
                        location.reload();
                    }
                });
                layer.full(ly)
            } else if (layEvent === 'BBStatistics') {
                layer.open({
                    type: 2,
                    title: '查看技术统计',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['100%', '100%'],
                    content: 'BBStatistics.html?MatchID=' + data.MatchID,
                    success: function (layero, index) {


                    },
                    end: function () {
                        location.reload();
                    }
                });
            }
        });
        axios.get('http://svcsa.org/BBSeason', {}).then(function (response) {
            console.log(response);
            $.each(response.data.data, function (index, item) {
                $('#Season').append('<option value="' + item.SeasonID + '">' + item.SeasonName + '</option>');
            });
            form.render();
        })
            .catch(function (error) {
                console.log(error);
            });
            

//            需要修改路径
        form.on('select(Season)', function (data) {

            table.reload('test', {
                // where: { //设定异步数据接口的额外参数，任意设
                //     // SeasonID: data.value,
                //     url: '../bbseason/' + data.value + '/bbplayer',
                // },
                url: 'http://svcsa.org/bbmatch?seasonid='+data.value,
                parseData: function (res) {
                    console.log(res)
                    return {
                        "code": 0, //解析接口状态
                        "msg": '', //解析提示文本
                        "count": res.totalcount, //解析数据长度
                        "data": res.data //解析数据列表
                    };
                },
                method: 'get',
                request: {
                    page: 'curr',
                    pagesize: 'nums' //每页数据量的参数名，默认：limit
                },
                title: '用户数据表',
                cols: [
                    [{
                        field: 'MatchID',
                        title: 'ID',
                        width: 70,
                        fixed: 'left',
                        unresize: true,
                        sort: true,
                    }, {
                        field: 'TeamAName',
                        title: '主队名',
                        width: 150,
                    }, {
                        field: 'TeamBName',
                        title: '客队名',
                        width: 150,
                    }, {
                        field: 'ScoreTeamA',
                        title: '主队分数',
                        width: 90,
                    }, {
                        field: 'ScoreTeamB',
                        title: '客队分数',
                        width: 90,
                    }, {
                        field: 'State',
                        title: '比赛状态',
                        width: 90,
                        toolbar: '#orderListBar'
                    }, {
                        field: 'StartTime',
                        title: '比赛时间',
                        width: 170,
                    },
                        //     {
                        //     field: 'Report',
                        //     title: '战报',
                        //     width: 150,
                        // },
                        //     {
                        //     field: 'VideoSrc',
                        //     title: '视频链接',
                        //     width: 150,
                        // },
                        {
                            field: 'SeasonName',
                            title: '赛季',
                            width: 200,
                        }, {
                        title: '查看比赛图片',
                        width: 120,
                        toolbar: '#BBPicture'
                    },
                        {
                            title: '查看技术统计',
                            width: 120,
                            toolbar: '#BBStatistics'
                        }, {
                        title: '操作',
                        width: 120,
                        toolbar: '#barDemo'
                    }]
                ],
                limit: 100,
                page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                    layout: ['count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                    //,curr: 5 //设定初始在第 5 页
                    , groups: 1 //只显示 1 个连续页码
                    , first: false //不显示首页
                    , last: false //不显示尾页

                }
            });
        });
    });
</script>